﻿using System.Collections.Generic;
using System.Linq;
using KLS.PPDS.Core.Entity;
using KLS.PPDS.Data.Database.Repository.RepositoryInterfaces;

namespace KLS.PPDS.Data.Database.Repository.EntityRepository
{
    public class PublicationRepository : LinqRepository<Publication>, IPublicationRepository
    {
        #region IPublicationRepository Members

        public IEnumerable<Publication> GetPublication(int customerId, int year, int month)
        {
            var rsl = FindAll().Where(c=>c.IsDeleted==false);

            if (customerId > 0)
            {
                rsl = rsl.Where(c => c.CompanyId == customerId);
            }

            if (year > 0)
            {
                rsl = rsl.Where(c => c.Year == year);
            }

            if (month > 0)
            {
                rsl = rsl.Where(c => c.Month == month);
            }

            return rsl.AsEnumerable();
        }

        public IEnumerable<Publication> GetPublicationForTaskAssigned(List<int> companyIds, int customerId, int year, int month)
        {
            var rsl = FindAll().Where(c => c.IsDeleted == false);

            rsl = from l in rsl
                  where companyIds.Contains(l.CompanyId)
                  select l;

            if (customerId > 0)
            {
                rsl = rsl.Where(c => c.CompanyId == customerId);
            }

            if (year > 0)
            {
                rsl = rsl.Where(c => c.Year == year);
            }

            if (month > 0)
            {
                rsl = rsl.Where(c => c.Month == month);
            }

            return rsl.AsEnumerable();
        }

        #endregion
    }
}
